<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>计划下达文号变更</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/Top.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/buttons.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/datagrid-detailview.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/util/jquery.cookie.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/YMLib.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/YWLib.js"></script>
    <script type="text/javascript">
        var pageSize_ = 20;
        $(function () {
            loadUnit1("gydw",$.cookie("unit"));
            loadDist1("xzqh",$.cookie("dist"));
            loadBmbm_xmnf('xmnf', '项目年份');
            loadBmbm_jsxz('jsxz');
            loadBmbm_zjly('zjly');
            queryRegulation();

            // parent.$('#problem').window({onResize: function (width, height) {
            //     console.log("width = " + width + "height:" + width);
            // }});

            // $(window).resize(function () {
            //     console.log("1111111111");
            //     $('#grid').datagrid('resize');
            // });
        });

        //获取编目编码
        function loadBmbm_xmnf(id, name) {
            var arr1=new Array();
            var arr2=new Array();
            var i=0;
            $.ajax({
                type:'post',
                async:false,
                url:'/jxcsxm/xtgl/getBmbmTreeByName2.do',
                data:'yhm='+ encodeURI(encodeURI(name)),
                dataType:'json',
                success:function(msg){
                    $('#' + id).combobox({
                        data:msg,
                        valueField : 'bmid',
                        textField : 'name',
                        multiple:true,
                        editable:false,
                        formatter:function(row){
                            arr1[i]=row.id;
                            arr2[i]=row.bmid;
                            i++;
                            var opts = $(this).combobox('options');
                            return '<input id="'+id+row.id+'" type="checkbox" class="combobox-checkbox">' + row[opts.textField];
                        },
                        onSelect:function(record){
                            var opts = $(this).combobox('options');
                            if(record[opts.valueField]==""){
                                var values =new Array();
                                var datas = $('#' +id).combobox("getData");
                                $.each(datas,function(index,item){
                                    values.push(item.bmid);
                                    $('#'+id+item.id).attr('checked', true);
                                });
                                $('#' +id).combobox("setValues",values);
                            }else{
                                $('#'+id+record.id).attr('checked', true);
                            }
                        },
                        onUnselect:function(record){
                            var opts = $(this).combobox('options');
                            var datas = $('#' +id).combobox("getData");
                            var values = $('#' +id).combobox("getValues");
                            $('#' +id).combobox("clear");
                            if(record[opts.valueField]!=""){
                                if(jQuery.inArray("",values)>=0){
                                    values.splice(jQuery.inArray("",values),1);
                                }
                                $.each(datas,function(index,item){
                                    if(jQuery.inArray(item.bmid,values)<0){
                                        $('#'+id+item.id).attr('checked', false);
                                    }
                                });
                                $('#' +id).combobox("setValues",values);
                            }else{
                                $.each(datas,function(index,item){
                                    $('#'+id+item.id).attr('checked', false);
                                });
                            }
                        },
                        onLoadSuccess:function(){
                            var values =new Array();
                            var datas = $('#' +id).combobox("getData");
                            $.each(datas,function(index,item){
                                values.push(item.value);
                                $('#id'+id+item.value).attr('checked', true);
                            });
                        }
                    });
                }
            });
        }

        function loadBmbm_zjly(id) {
            var years=[];
            years.push({text:'全部',value:''});
            years.push({text:'资金到位', value: '100'});
            years.push({text:'资金拨付', value: '102'});
            $('#' + id).combobox({
                data:years,
                valueField : 'value',
                textField : 'text',
                multiple:true,
                editable:false,
                formatter:function(row){
                    var opts = $(this).combobox('options');
                    return '<input id="id'+row.value+'" type="checkbox" class="combobox-checkbox">' + row[opts.textField];
                },
                onSelect:function(record){
                    var opts = $(this).combobox('options');
                    if(record[opts.valueField]==""){
                        var values =new Array();
                        var datas = $('#' +id).combobox("getData");
                        $.each(datas,function(index,item){
                            values.push(item.value);
                            $('#id'+item.value).attr('checked', true);
                        });
                        $('#' +id).combobox("setValues",values);
                    }else{
                        $('#id'+record.value).attr('checked', true);
                    }
                },
                onUnselect:function(record){
                    var opts = $(this).combobox('options');
                    var datas = $('#' +id).combobox("getData");
                    var values = $('#' +id).combobox("getValues");
                    $('#' +id).combobox("clear");
                    if(record[opts.valueField]!=""){
                        if(jQuery.inArray("",values)>=0){
                            values.splice(jQuery.inArray("",values),1);
                        }
                        $.each(datas,function(index,item){
                            if(jQuery.inArray(""+item.value,values)<0){
                                $('#id'+item.value).attr('checked', false);
                            }
                        });
                        $('#' +id).combobox("setValues",values);
                    }else{
                        $.each(datas,function(index,item){
                            $('#id'+item.value).attr('checked', false);
                        });
                    }
                },
                filter: function(q, row){
                    var opts = $(this).combobox('options');
                    return row[opts.textField].indexOf(q) != -1;
                }
            });
        }

        function loadBmbm_jsxz(id, name,str) {
            var arr1=new Array();
            var arr2=new Array();
            var i=0;
            $.ajax({
                type:'post',
                async:false,
                url:'/jxcsxm/funds/getJsxzTreeByName.do',
                dataType:'json',
                success:function(msg){
                    var years=[];
                    years.push({text:'全部',value:''});
                    if(msg!=null) {
                        for ( var i = 0; i < msg.length; i++) {
                            years.push({text:msg[i].name,value: "zhanxy"+(1+i)});
                        }
                    }
                    $('#' + id).combobox({
                        data:years,
                        valueField : 'value',
                        textField : 'text',
                        multiple:true,
                        editable:false,
                        formatter:function(row){
                            var opts = $(this).combobox('options');
                            return '<input id="id'+row.value+'" type="checkbox" class="combobox-checkbox">' + row[opts.textField];
                        },
                        onSelect:function(record){
                            var opts = $(this).combobox('options');
                            if(record[opts.valueField]==""){
                                var values =new Array();
                                var datas = $('#' +id).combobox("getData");
                                $.each(datas,function(index,item){
                                    values.push(item.value);
                                    $('#id'+item.value).attr('checked', true);
                                });
                                $('#' +id).combobox("setValues",values);
                            }else{
                                $('#id'+record.value).attr('checked', true);
                            }
                        },
                        onUnselect:function(record){
                            var opts = $(this).combobox('options');
                            var datas = $('#' +id).combobox("getData");
                            var values = $('#' +id).combobox("getValues");
                            $('#' +id).combobox("clear");
                            if(record[opts.valueField]!=""){
                                if(jQuery.inArray("",values)>=0){
                                    values.splice(jQuery.inArray("",values),1);
                                }
                                $.each(datas,function(index,item){
                                    if(jQuery.inArray(""+item.value,values)<0){
                                        $('#id'+item.value).attr('checked', false);
                                    }
                                });
                                $('#' +id).combobox("setValues",values);
                            }else{
                                $.each(datas,function(index,item){
                                    $('#id'+item.value).attr('checked', false);
                                });
                            }
                        },
                        filter: function(q, row){
                            var opts = $(this).combobox('options');
                            return row[opts.textField].indexOf(q) != -1;
                        }
                    });
                }
            });
        }

        function closeWindow_reg(){
            parent.$('#problem').window('destroy');
        }

        function queryRegulation() {
            var xzqhdm=$("#xzqh").combotree("getValues");
            var xzqhstr = '';
            if(xzqhdm.length==0){
                xzqhstr= $.cookie("dist2");
            }else if(xzqhdm.length==1){
                if(xzqhdm[0].substr(xzqhdm[0].length-2,xzqhdm[0].length)=="00") xzqhdm[0]=xzqhdm[0].substr(0,xzqhdm[0].length-2);
                if(xzqhdm[0].substr(xzqhdm[0].length-2,xzqhdm[0].length)=="00") xzqhdm[0]=xzqhdm[0].substr(0,xzqhdm[0].length-2);
                xzqhstr=xzqhdm[0] ;
            }else{
                xzqhstr= xzqhdm.join(',');
            }
            var gydw=$("#gydw").combotree("getValues");
            var gydwstr = '';
            if(gydw.length==0){
                if($.cookie("unit2")=='_____36')
                    gydwstr=36;
                else gydwstr= $.cookie("unit2");
            }else if(gydw.length==1){
                if(gydw[0].substr(gydw[0].length-2,gydw[0].length)=="00") gydw[0]=gydw[0].substr(0,gydw[0].length-2);
                if(gydw[0].substr(gydw[0].length-2,gydw[0].length)=="00") gydw[0]=gydw[0].substr(0,gydw[0].length-2);
                gydwstr=gydw[0] ;
            }else{
                gydwstr= gydw.join(',');
            }

            var xmnf=$("#xmnf").combobox("getValues").join(",");
            if(xmnf.substr(0,1)==',') {
                xmnf=xmnf.substr(1,xmnf.length);
            }


            var jsxz=$("#jsxz").combobox("getText");
            if(jsxz.substr(0,1)==',') {
                jsxz=jsxz.substr(1,jsxz.length);
            }
            var zjly=$("#zjly").combobox("getText");
            if(zjly.substr(0,1)==',') {
                zjly=zjly.substr(1,zjly.length);
            }

            var params = {
                'xzqh': xzqhstr,
                'jsxz': jsxz,
                'gydwdm': gydwstr,
                'xmnf': xmnf,
                'zjly': zjly,
                'xmmc': $("#xmmc").val()
            };

            $('#grid').datagrid({
                url:'/jxcsxm/funds/queryjhDataBybgDel.do',
                striped:true,
                pagination:true,
                rownumbers:true,
                fitColumns: true,
                pageNumber:1,
                pageSize:pageSize_,
                checkOnSelect:true,
                height: $(window).height()-90,
                // width: $(window).width()-20,
                width:$('#searchField').width()+2,
                queryParams: params,
                onSelectPage: function (pageNumber, pageSize) {
                    pageSize_ = pageSize;
                },
                onBeforeLoad: function () {
                    pageSize_ = $("#grid").datagrid("options").pageSize;
                },
                columns:[[
                    {field:'gydw',title:'管养单位',width:180,align:'center'},
                    {field:'xzqh',title:'行政区划',width:100,align:'center'},
                    {field:'xmmc',title:'项目名称',width:200,align:'center'},
                    {field:'xmnf',title:'项目年份',width:60,align:'center'},
                    {field:'jsxz',title:'建设性质',width:100,align:'center'},
                    {field:'zjly',title:'资金来源',width:100,align:'center'},
                    {field:'desc',title:'变更描述',width:650,align:'center',
                        formatter: function (value,row,index) {
                            var html = "";
                            if (row.flag == '变更') {
                                var content = "项目名称【" + row.xmmc + "】的计划下达文号【" + row.jhxdwh + "】已变更, 请更新！";
                                html = "<span alt='" + content + "' title='" + content + "' style='color: royalblue; font-weight: bolder;'>" + content + "</span>";
                                // html = "<span style='color: royalblue; font-weight: bolder;'>项目名称【"+ row.xmmc + "】的计划下达文号【" + row.jhxdwh + "】已变更, 请更新！" +"</span>";
                            } else if (row.flag == '删除') {
                                var content = "项目名称【" + row.xmmc + "】的计划下达文号【" + row.jhxdwh + "】已删除, 请更新！";
                                html = "<span alt='" + content + "' title='" + content + "' style='color: firebrick; font-weight: bolder; '>" + content + "</span>";
                                // html = "<span style='color: firebrick; font-weight: bolder; '>项目名称【"+ row.xmmc + "】的计划下达文号【" + row.jhxdwh + "】已删除, 请更新！" +"</span>";
                            }
                            return html;
                        }
                    }
                ]]
            });
        }
    </script>
</head>
<body>
    <table width="99.9%" border="0" style="margin-top: 1px; margin-left: 1px;" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left" style="padding-left:10px;padding-right: 10px; padding-top: 5px;">
                <fieldset id="searchField" style="width:99.9%; text-align: left; vertical-align: middle;">
                    <legend style="padding: 0 0 0 0; font-weight: bold; color: Gray; font-size: 12px;">
                        <font style="color: #0866A0; font-weight: bold"></font>
                    </legend>
                    <div>
                        <table style="margin:4px; vertical-align:middle;" cellspacing="0" class="abgc_td" >
                            <tr height="28">
                                <td align="right">行政区划：</td>
                                <td><select id="xzqh" style="width:165px;"></select></td>
                                <td align="right">管养单位：</td>
                                <td><select id="gydw" style="width:165px;"></select></td>
                                <td align="right">项目年份：</td>
                                <td><select id="xmnf" style="width: 100px;"></select></td>
                                <td align="right">项目名称：</td>
                                <td><input name="xmmc" type="text" id="xmmc" style="width:140px;" /></td>
                                <td align="right">资金来源：</td>
                                <td><select name="jsxz" id="zjly" style="width:100px;" ></select></td>
                                <td align="right">建设性质：</td>
                                <td><select name="jsxz" id="jsxz" style="width:100px;" ></select></td>
                                <td colspan="2">
                                    <a id='mybuttion1' style="margin-top: 5px;margin-bottom: 1px;" href="javascript:queryRegulation()" onmouseover="szgq('button button-tiny button-glow button-rounded button-raised button-primary','mybuttion1')" onmouseout="szgq('button button-tiny button-rounded button-raised button-primary','mybuttion1')"  class="button button-tiny button-rounded button-raised button-primary">查询</a>
                                </td>
                            </tr>
<%--                            <tr height="28">--%>
<%--                                --%>
<%--                            </tr>--%>
                        </table>
                    </div>
                </fieldset>
            </td>
        </tr>
        <tr>
            <td style="padding-left: 10px; font-size:12px;">
                <div><table id="grid"></table></div>
            </td>
        </tr>
        <tr>
            <td colspan="12" align="center">
                <a id='mybuttion2' style="margin-left: 1px;margin-bottom: 1px;margin-top: 10px;" href="javascript:closeWindow_reg()" onmouseover="szgq('button button-tiny button-glow button-rounded button-raised button-primary','mybuttion2')" onmouseout="szgq('button button-tiny button-rounded button-raised button-primary','mybuttion2')"  class="button button-tiny button-rounded button-raised button-primary">关闭</a>
            </td>
        </tr>
    </table>
</body>
</html>